package com.kgc.crowd.distributioncrowddatabaseprovider.controller;

import com.kgc.crowd.distributioncrowdcommon.api.DataBaseOperationRemoteService;
import com.kgc.crowd.distributioncrowdcommon.api.RedisOperationRemoteService;
import com.kgc.crowd.distributioncrowdcommon.pojo.ResultEntity;
import com.kgc.crowd.distributioncrowdcommon.pojo.TagPO;
import com.kgc.crowd.distributioncrowdcommon.pojo.TypePO;
import com.kgc.crowd.distributioncrowdcommon.util.CrowdConstant;
import com.kgc.crowd.distributioncrowdcommon.vo.ProjectVO;
import com.kgc.crowd.distributioncrowddatabaseprovider.service.ProjectService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/database/provider")
public class ProjectController {
    @Resource
    ProjectService projectService;


    @RequestMapping("/save/project/remote/{memberId}")
    public ResultEntity<String> saveProjectRemote(
            @RequestBody ProjectVO projectVO,
            @PathVariable("memberId") String memberId) {

        try {
            projectService.saveProject(projectVO, memberId);

            return ResultEntity.successNoData();
        } catch (Exception e) {
            e.printStackTrace();

            return ResultEntity.failed(e.getMessage());
        }

    }

    @RequestMapping("/select/all/type")
    public ResultEntity<List<TypePO>> selectAllType() {

        try {
            List<TypePO> typePOS = projectService.selectTypePO();

            return   ResultEntity.successWithData(typePOS);
        } catch (Exception e) {
            e.printStackTrace();

            return ResultEntity.failed(e.getMessage());
        }

    }


    @RequestMapping("/select/all/tag")
    public ResultEntity<List<TagPO>> selectAllTag() {

        try {
            List<TagPO> tagPOS = projectService.selectTagPO();

            return   ResultEntity.successWithData(tagPOS);
        } catch (Exception e) {
            e.printStackTrace();

            return ResultEntity.failed(e.getMessage());
        }

    }

}
